﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Barbar.UrlGuard.Dal.Persist {
  public class RecordHeader {
    private long m_NextRecordPosition;
    private int m_RecordSize;
    private int m_RecordsCount;
    private int m_ChunkSize;
    private Guid m_RecordType;
    // not serialized
    private long m_FilePosition;

    public const int BINARY_SIZE = 36;

    public RecordHeader() {
    }

    public RecordHeader(int recordSize, int chunkSize, Guid recordType) {
      m_RecordSize = recordSize;
      m_ChunkSize = chunkSize;
      m_RecordType = recordType;
    }

    public long NextRecordPosition {
      get { return m_NextRecordPosition; }
      set { m_NextRecordPosition = value; }
    }

    public int RecordSize {
      get { return m_RecordSize; }
      set { m_RecordSize = value; }
    }

    public int RecordsCount {
      get { return m_RecordsCount; }
      set { m_RecordsCount = value; }
    }

    public int ChunkSize {
      get { return m_ChunkSize; }
      set { m_ChunkSize = value; }
    }

    public Guid RecordType {
      get { return m_RecordType; }
      set { m_RecordType = value; }
    }

    public long FilePosition {
      get { return m_FilePosition; }
      set { m_FilePosition = value; }
    }

    public bool CanAddNewRecord() {
      return (RecordSize + 1) * RecordsCount + BINARY_SIZE <= m_ChunkSize;
    }

    public int GetRecordOffset() {
      return (RecordSize * RecordsCount) + BINARY_SIZE;
    }
  }
}
